package main

import "fmt"

func main() {
	s0 := []int{10, 30, 50, 70, 90, 110, 120, 130}
	// s1 := make([]int, 5, 8)
	s1 := s0[:5] // len=5-0=5 cap=8
	fmt.Printf("s1 %p, %p, l=%-2d, c=%-2d, %v \n", &s1, &s1[0], len(s1), cap(s1), s1)

	s2 := s1
	fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v \n", &s2, &s2[0], len(s2), cap(s2), s2)

	s3 := s1[:]
	fmt.Printf("s3 %p, %p, l=%-2d, c=%-2d, %v \n", &s3, &s3[0], len(s3), cap(s3), s3)
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~")

	s4 := s1[1:] // 掐头 len = 5 - 1 = 4 end缺省值是什么？len
	fmt.Printf("s4 %p, %p, l=%-2d, c=%-2d, %v \n", &s4, &s4[0], len(s4), cap(s4), s4)

	s5 := s1[1:4] // len=4-1=3 cap = 7
	fmt.Printf("s5 %p, %p, l=%-2d, c=%-2d, %v \n", &s5, &s5[0], len(s5), cap(s5), s5)

	s6 := s1[:4]
	fmt.Printf("s6 %p, %p, l=%-2d, c=%-2d, %v \n", &s6, &s6[0], len(s6), cap(s6), s6)

	s7 := s1[5:]
	fmt.Printf("s7 %p, l=%-2d, c=%-2d, %v \n", &s7, len(s7), cap(s7), s7)

	// s8 := s1[6:] // len= cap= 错误 s1[6:5]
	// fmt.Printf("s8 %p, %p, l=%-2d, c=%-2d, %v \n", &s8, &s8[0], len(s8), cap(s8), s8)

	// start/end最大值为 cap，不是len
	// start 缺省值是 0
	// end 的缺省值是 len 不是 cap

	s9 := s1[6:7] // len=7-6=1 cap=2
	fmt.Printf("s9 %p, %p, l=%-2d, c=%-2d, %v \n", &s9, &s9[0], len(s9), cap(s9), s9)

	s10 := s1[6:8] // len=2 cap=2
	fmt.Printf("s10 %p, %p, l=%-2d, c=%-2d, %v \n", &s10, &s10[0], len(s10), cap(s10), s10)

	// s11 := s1[6:6] len=0 cap=2
	// s12 := s1[4:] len=1 cap=4 [90]
	// s13 := s1[4:8] len=4 cap=4 [90 110 120 130]
	// s14 := s1[7:7] len=0 cap=1 []
	// s15 := s1[7:] // 语法错误
	// s16 := s1[8:8] len=0 cap=0 []
	// s17 := s1[:0] len=0 cap=8 []

}
